/*
 * StopWatchTest.h
 *
 *  Created on: Jan 30, 2010
 *      Author: lapointj
 */

#ifndef STOPWATCHTEST_H_
#define STOPWATCHTEST_H_

#include <cxxtest/TestSuite.h>
#include "StopWatch.h"

using namespace LinuxStopWatch;

class StopWatchTest : public CxxTest::TestSuite
{
private:
	void longRunningFunction(int multiplier)
	{
	   int maxX = 10 * multiplier;
	   int maxY = 10 * multiplier;

	   double result;

	   for (int x = 0; x < maxX; ++x)
	   {
	      for (int y = 0; y < maxY; ++y)
	      {
	         result = sqrt((double) (x * x) + (double) (y * y));
	      }
	   }
	}

public:
	void testSingleBasic()
	{
		StopWatch stopWatch;
		TS_ASSERT(stopWatch.start() == 0);
		longRunningFunction(300);
		TS_ASSERT(stopWatch.stop() == 0);
		TS_ASSERT(stopWatch.getElapsedTime() > 0.0);
	}

	void testDoubleBasic()
	{
		double timeOne = 0.0;
		double timeTwo = 0.0;

		StopWatch stopWatch;
		TS_ASSERT(stopWatch.start() == 0);
		longRunningFunction(300);
		TS_ASSERT(stopWatch.stop() == 0);
		TS_ASSERT((timeOne = stopWatch.getElapsedTime()) > 0.0);

		TS_ASSERT(stopWatch.start() == 0);
		longRunningFunction(700);
		TS_ASSERT(stopWatch.stop() == 0);
		TS_ASSERT((timeTwo = stopWatch.getElapsedTime()) > 0.0);

		TS_ASSERT(timeTwo > timeOne);
	}

	void testNoStop()
	{
		StopWatch stopWatch;
		TS_ASSERT(stopWatch.start() == 0);
		longRunningFunction(300);
		TS_ASSERT(stopWatch.getElapsedTime() > 0.0);
	}

	void testNoStartStop()
	{
		StopWatch stopWatch;
		TS_ASSERT(stopWatch.getElapsedTime() == LinuxStopWatch::timerNeverStarted);
	}

	void testNoStart()
	{
		StopWatch stopWatch;
		TS_ASSERT(stopWatch.stop() == LinuxStopWatch::isTimerNotSet);
		TS_ASSERT(stopWatch.getElapsedTime() == LinuxStopWatch::timerNeverStarted);
	}
};

#endif /* STOPWATCHTEST_H_ */
